/*
 * Copyright (c) 2024 Shenzhen Kaihong Digital Industry Development Co., Ltd.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
 
#ifndef NEARLINK_SLE_IPERF_COMMON_H
#define NEARLINK_SLE_IPERF_COMMON_H
#ifdef __cplusplus
extern "C" {
#endif // __cplusplus
#include <stdint.h>
//魔数
#define SLE_KHT_MAGIC_NUM 0x5a6b7d4b
//统计打流的消息id
#define SLE_KHT_COMM_RX_PAYLOAD  0x0012
//打流结束消息id rx-下行
#define SLE_KHT_COMM_RX_END  0x0013
//client请求server开始发包
#define SLE_KHT_COMM_CLIENT_REQ_SERVER  0x0011
//client向server发包
#define SLE_KHT_COMM_CLIENT_IPERF_TO_SERVER  0x0010
//最大连接数 1 V SLE_KHT_MAX_ADDR_RESULTS
#define SLE_KHT_MAX_ADDR_RESULTS 20
//每200个包记录一次吞吐
#define SLE_KHT_IPERF_ONCE_PACK_NUM 100
//发包轮数
#define SEND_STEP 5
//发包数
#define ALL_SEND_PACKAGE 1000
//发送end包retry次数
#define SEND_END_RETRY 1
//打流时间
#define IPERF_TIME 0
//时延
#define COUNT_TIME_DELAY_ID 0x0016
#define IPERF_RTT 0x0017
//异常断开重连
#define RETRY_CONNECT 6
#define RETRY_CONNECT_TIME_S 20

typedef struct {
    uint32_t magic_num; // 魔数  SLE_KHT_MAGIC_NUM 0x5a6b7d4b
    uint16_t msgid;  // 消息ID
    uint16_t length; // 消息总长度(包括消息头)
    uint32_t seqid;  // 消息序列号 自加
    uint16_t sendstep;// 发包轮数
    uint16_t allsendpackage;// 一轮发包数
    uint16_t oncecount; // 每oncecount个包记录一次吞吐
    uint32_t iperftime;//打流时间
    uint32_t iperfdelaytime;//间隔打流时间
    uint16_t conenctId;//此消息对应的连接id
} sle_kht_msghdr;

typedef struct {
    uint32_t total_count;   //收包数量
    uint64_t total_bytes;   //收包字节
    uint64_t begin_tv_us;   //开始计时
    uint64_t end_tv_us;     //结束计时
    uint32_t seq_start;     //开始包
    uint32_t seq_stop;      //结束包
    uint32_t total_drops;   //丢包
} sle_kht_txrx_stat_t;

typedef struct {
    uint16_t connect_id;   //连接id
    uint16_t valid; // 是否是有效的连接
    uint32_t start_seq;    //开始包
    uint32_t last_seq;     //上一个包
    uint8_t device_addr[6];
} tx_context_t;

#ifdef __cplusplus
}
#endif // __cplusplus
#endif //NEARLINK_SLE_IPERF_COMMON_H
